//
//  main.m
//  NSString字符串
//
//  Created by mir_yan on 2018/10/1.
//  Copyright © 2018年 hakeem. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // 多行字面量
//        NSString * str = @"123"
//        @"456"
//        @"78";
//
//        NSLog(@"%@", str);
//        NSString * string = @"123sdff123";
//        NSRange rang = {3, 2};
//        NSString* newStr = [string
//                            substringWithRange:rang];
//
//        NSLog(@"%@", newStr);
//        ---------------
//        NSString * string = @"123sdff123";

//        NSCaseInsensitiveSearch 忽略大小写
//        NSRange range = [string rangeOfString:@"sdw"
//                                      options:NSCaseInsensitiveSearch];
//        if (range.length == 0) {
//            NSLog(@"没有找到");
//        }
//        if (range.location == NSNotFound) {
//            NSLog(@"没有找到。");
//        }
//        NSLog(@"%@", NSStringFromRange(range));
//
//        ----------------
        // 组合字符串
//        NSString * string = @"abc";
//        NSString * newString = [string stringByAppendingFormat:@"vvv"];
        // 将整型转字符串
//        NSString * newString = [string stringByAppendingFormat:@"def%d", 12];
        // 拼接字符串
//        NSString * newString = [string stringByAppendingString:@"def"];
        // 填充
//        NSString * newString = [string stringByPaddingToLength:10 withString:@"1" startingAtIndex:0];
//        NSLog(@"%@", newString);
        
//        -------------------
        // 分割 字符串 -> 数组
//        NSString* string = @"abc-bdc-sdl";
//        NSArray* array = [string componentsSeparatedByString:@"-"];
//        NSLog(@"%@", array);
        
        // 数组 拼接成字符串
//        NSArray* array = @[@"a",@"b",@"c"];
//        NSString * string = [array componentsJoinedByString:@"-"];
//        NSLog(@"%@", string);
        
        // 去空格
//        NSString* string = @"abc-bdc-sdl  ";
//        string = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
//        NSLog(@"%@", string);
        
        // 替换 替换“”
//        NSString* string = @"lixuehuan";
//        NSString* newStr = [string stringByReplacingOccurrencesOfString:@"li" withString:@"zhang"];
//        NSLog(@"%@", newStr);
        
        // 替换区间
//        NSString * string = @"halihaliabcshanghai";
//        NSRange rang = {4, 4};
//        string = [string stringByReplacingCharactersInRange:rang withString:@"beijing"];
//        NSLog(@"%@", string);
        
        // 比较
        NSString* string1 = @"abc";
        NSString* string2 = @"ABC";
        
//        [string1 hasPrefix:string2];
        
//        NSComparisonResult rs = [string1 compare:string2];
        // 忽略大小写
        NSComparisonResult rs = [string1 compare:string2 options:NSCaseInsensitiveSearch];
        if (rs == NSOrderedAscending) {
            NSLog(@"string1 < string2");
        } else if (rs == NSOrderedSame) {
            NSLog(@"string1 == string2");
        } else {
            NSLog(@"string1 > string2");
        }
        
        // 小写转大写
        // lowercaseString 大写转小写
        
        NSString * ssstr = @"abc";
//        [ssstr lowercaseString]
        NSString * newSSStr = [ssstr uppercaseString];
        NSLog(@"%@", newSSStr);
        
//        字符串 int 互转
        NSString * str11 = [NSString stringWithFormat:@"%d", 123];
        NSLog(@"%@", str11);
        
        int num = [str11 intValue];
        NSLog(@"%d", num);
        
        double numd = [str11 doubleValue];
        NSLog(@"%f", numd);
    }
    return 0;
}
